home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 32 / sot.zip / SOTV.C < prev   
Text File  |  1988-08-23  |  6KB  |  251 lines

  1. /********** The Son of Tetris Project ************/
  2.  
  3. /************ VIDEO/DISPLAY functions ***********/
  4.  
  5.  
  6. #include <conio.h>
  7. #include <dos.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. #include "sot.h"
  12.  
  13. #define COFF 28       /* Column offset main display */
  14. #define LOFF 0        /* Line offset */
  15.  
  16. #define SCOR_COFF 55
  17. #define SCOR_LOFF 5
  18. #define CRIB_COFF 3
  19. #define CRIB_LOFF 3
  20.  
  21. #define HOT_CHAR '░'
  22.  
  23. static unsigned     vseg;                     /* Video segment */
  24. static void        *screen_buf;               /* Screen held here */
  25. static int          x_cur_pos, y_cur_pos;     /* Initial cursor position */
  26. static int          cursor_val = FALSE;
  27.  
  28. const  unsigned char FILL_CHAR = '∙';
  29.  
  30. #define vpoke(adr, chr)  poke(vseg, adr, chr)
  31.  
  32.  
  33.  
  34. static int vmode(void)
  35. {
  36.   union REGS rg;
  37.  
  38.   rg.h.ah = 15;
  39.   int86(0x10,&rg, &rg);
  40.   return rg.h.al;
  41. } /* vmode */
  42.  
  43.  
  44.  
  45. static int get_cursor_state(void)
  46. {
  47.   union REGS rg;
  48.  
  49.   rg.h.ah = 15;
  50.   int86(0x10,&rg, &rg); /*  get current display page to bh */
  51.   rg.h.ah = 3;
  52.   int86(0x10,&rg, &rg); /*  get current display page to bh */
  53.   return rg.x.cx;
  54. } /* get_cursor_state */
  55.  
  56.  
  57.  
  58. static void set_cursor_state(int state)
  59. {
  60.   union REGS rg;
  61.  
  62.   rg.h.ah = 1;
  63.   rg.x.cx = state;
  64.   int86(0x10,&rg, &rg);
  65. } /* set_cursor_state */
  66.  
  67.  
  68.  
  69. void cursor_off(void)
  70. {
  71.   if (!cursor_val)
  72.     cursor_val = get_cursor_state();
  73.   set_cursor_state(cursor_val | 0x2000);
  74. }
  75.  
  76.  
  77. void cursor_on(void)
  78. {
  79.   set_cursor_state(cursor_val);
  80. }
  81.  
  82.  
  83.  
  84. void  p_arena(int left,int top,int right,int bottom)
  85. {
  86.   static unsigned start_offset = ((SCRW * (LOFF - 1)) + COFF) * 2;
  87.   register unsigned x, col_offset, row_offset;
  88.   long  attribute;
  89.  
  90.   left = (left > 0) ? left : 1;  /* Force display only within boundaries */
  91.   right = (right < BLW-1) ? right : BLW-2;
  92.   top = (top > 0) ? top : 1;
  93.   bottom = (bottom < BLH-1) ? bottom : BLH-2;
  94.  
  95.   for (row_offset = start_offset + 2 * SCRW * top + 4 * left;
  96.        top <= bottom;
  97.        top++, row_offset += 2 * SCRW)
  98.   {
  99.     for (col_offset = row_offset, x = left;
  100.      x <= right;
  101.      x++,col_offset +=4)
  102.     {
  103.       switch(arena[x][top])
  104.       {
  105.         case CLEAR:
  106.       attribute = (x & 1) ?  ' ': FILL_CHAR;
  107.           attribute |= ((BLACK << 4) + WHITE) << 8;
  108.           vpoke(col_offset,attribute);
  109.           vpoke(col_offset+2,attribute & 0xFF00);
  110.       break;
  111.  
  112.         case BORDER:
  113.       attribute = '?';
  114.           attribute |= ((BLACK << 4) + WHITE) << 8;
  115.       break;
  116.  
  117.         default:
  118.       if (arena[x][top] > BLINK)
  119.       {
  120.         attribute = HOT_CHAR;
  121.             attribute |= ((arena[x][top] << 4) + (arena[x][top] | DARKGRAY))
  122.                 << 8;
  123.       } /* hot object */
  124.       else
  125.       {
  126.         attribute = ' ';
  127.         attribute |= ((arena[x][top] << 4) + BLACK) << 8;
  128.       }
  129.           vpoke(col_offset,attribute);
  130.           vpoke(col_offset+2,attribute);
  131.       break;
  132.  
  133.       } /* switch */
  134.     } /* for each column */
  135.   } /* for each row */
  136.  
  137. } /* p_arena */
  138.  
  139.  
  140.  
  141. void      v_kill_row(int  t_row)
  142. {
  143.   window(COFF+ 3, LOFF + 1, COFF + (BLW-1) * 2, LOFF + t_row);
  144.   gotoxy(1,1);
  145.   insline();
  146.   window(1,1,80,25);
  147.   p_arena(1,1,BLW-2,1);
  148. }         /* v_kill_row */
  149.  
  150.  
  151.  
  152. static void p_surround(void)
  153. {
  154.   int i;
  155.   for (i = (LOFF - 1) + 2; i < (LOFF - 1) + BLH; i++)
  156.   {
  157.     gotoxy(COFF + 2,i); putch('║');
  158.     gotoxy(COFF+ 2 * BLW-1,i); putch('║');
  159.   }
  160.   gotoxy(COFF + 3, (LOFF - 1) + BLH);
  161.   for (i = 0; i < 2 * (BLW - 2); i++)
  162.     putch('═');
  163.   gotoxy(COFF + 2, (LOFF - 1) + BLH); putch('╚');
  164.   gotoxy(COFF + 2 * BLW - 1, (LOFF - 1) + BLH); putch('╝');
  165.  
  166. } /* p_surround  */
  167.  
  168.  
  169. void  init_video(void)
  170. {
  171.   screen_buf = malloc(80 * 25 * 2);
  172.   gettext(1,1,80,25,screen_buf);
  173.   x_cur_pos = wherex();
  174.   y_cur_pos = wherey();
  175.   cursor_off();
  176.   clrscr();            /* Clear screen */
  177.   vseg = (vmode() == 7) ? 0xB000:0xB800;  /* Set monochrome/colour segment */
  178.  
  179.   p_surround();
  180.   gotoxy(SCOR_COFF,SCOR_LOFF);
  181.   cprintf("Level :");
  182.   gotoxy(SCOR_COFF,SCOR_LOFF+1);
  183.   cprintf("Score :");
  184.   gotoxy(SCOR_COFF,SCOR_LOFF+2);
  185.   cprintf("Lines :");
  186.   gotoxy(SCOR_COFF,SCOR_LOFF+4);
  187.   cprintf("Next shape :");
  188.  
  189.   gotoxy(CRIB_COFF,CRIB_LOFF);
  190.   cprintf("      SOT Crib");
  191.   gotoxy(CRIB_COFF,CRIB_LOFF+2);
  192.   cprintf("7: Left        P: Pause");
  193.   gotoxy(CRIB_COFF,CRIB_LOFF+3);
  194.   cprintf("8: Rotate      S: Sound");
  195.   gotoxy(CRIB_COFF,CRIB_LOFF+4);
  196.   cprintf("9: Right     ESC: Abort");
  197.   gotoxy(CRIB_COFF,CRIB_LOFF+5);
  198.   cprintf("4: Drop    SPACE: Drop");
  199.   gotoxy(CRIB_COFF,CRIB_LOFF+6);
  200.   cprintf("6: Level ");
  201.  
  202.  
  203. }   /* init_video */
  204.  
  205.  
  206. void  end_video(void)
  207. {
  208.   puttext(1,1,80,25,screen_buf);
  209.   gotoxy(x_cur_pos,y_cur_pos);
  210.   cursor_on();
  211. }     /* end_video */
  212.  
  213.  
  214. void  update_score(unsigned level,
  215.                    long     score,
  216.            unsigned lines_del,
  217.            SHP_TYPE *next_sh,
  218.            int show_shape)
  219. {
  220.   int x,y, *map_ptr;
  221.   gotoxy(SCOR_COFF + 8,SCOR_LOFF);
  222.   cprintf("%7u",level);
  223.   gotoxy(SCOR_COFF + 8,SCOR_LOFF+1);
  224.   cprintf("%7ld",score);
  225.   gotoxy(SCOR_COFF + 8,SCOR_LOFF+2);
  226.   cprintf("%7u",lines_del);
  227.  
  228.   window(SCOR_COFF, SCOR_LOFF + 6,SCOR_COFF + 15, SCOR_LOFF + 10);
  229.   clrscr();
  230.   window(1,1,80,25);
  231.   if (show_shape)
  232.   {
  233.     map_ptr = next_sh -> map[0];
  234.     for (y = 0; y < next_sh ->ht; y++)
  235.     {
  236.       gotoxy(SCOR_COFF, SCOR_LOFF + 6 + y);
  237.       for (x = 0; x < next_sh ->wd; x++,map_ptr++)
  238.       {
  239.         if (*map_ptr)
  240.           textattr((next_sh ->col << 4) + BLACK);
  241.         else
  242.           textattr((BLACK << 4) + BLACK);
  243.  
  244.         putch(' '); putch(' ');
  245.       } /* for x */
  246.     } /* for y */
  247.   } /* if show_shape */
  248.   textattr((BLACK << 4) + LIGHTGRAY);
  249.  
  250. }       /* update_score */
  251.